﻿using System.Linq;
using Framework.Poco;
using Shell.DomainDot;
using System.Collections.Generic;
using System;

namespace Framework.Domain
{
    public class AgencyManagerContext : DomainDotBase
    {
        public WithAll<Agency> Agencies { get; set; }

        public WithAll<AgencyContext, Agency> AgencyContext { private get; set; }

        public IEnumerable<Agency> GetAllAgencies()
        {
            return this.Agencies;
        }

        /// <summary>
        /// 经销商删除
        /// </summary>
        public void Remove(Guid identity)
        {
            this.Agencies.Delete(identity);
            this.Agencies.Submit();
        }

        /// <summary>
        /// 设置是否通过验证
        /// </summary>
        public void SetVerification(Agency agency, bool isVerification)
        {
            var ag = this.Agencies.SingleOrDefault(a => a.Id == agency.Id);
            ag.IsVerification = isVerification;
            this.Agencies.Submit();
        }

        /// <summary>
        /// 设置等级
        /// </summary>
        public void SetLevel(Agency agency, int level)
        {
            var ag = this.Agencies.SingleOrDefault(a => a.Id == agency.Id);
            ag.Level = level;
            this.Agencies.Submit();
        }
    }
}
